package com.zhss.concurrency;

/**
 * @ClassName DoubleCheckDemo
 * @Description TODO
 * @Author leejiliang
 * @DateTime 2021/6/18 09:47
 * @Version 1.0
 */
public class DoubleCheckDemo {

	private static class InnerInstance {
		public static DoubleCheckDemo doubleCheckDemo = new DoubleCheckDemo();
	}

	public static DoubleCheckDemo getInstance3() {
		return DoubleCheckDemo.InnerInstance.doubleCheckDemo;
	}

	private  DoubleCheckDemo (){}
	private volatile DoubleCheckDemo doubleCheckDemo;


	public DoubleCheckDemo getInstance() {
		if (doubleCheckDemo == null) {
			synchronized (DoubleCheckDemo.class) {
				if (doubleCheckDemo == null) {
					doubleCheckDemo = new DoubleCheckDemo();
				}
			}
		}
		return doubleCheckDemo;
	}

	public synchronized DoubleCheckDemo getInstance1() {
		if (doubleCheckDemo == null) {
			doubleCheckDemo = new DoubleCheckDemo();
		}
		return doubleCheckDemo;
	}




}
